#include "humthread.h"

humthread::humthread(QObject *parent) : QObject(parent)
{
    socket = new QTcpSocket;
        connect(socket, &QTcpSocket::readyRead, this, [this]() {
            QByteArray data = socket->readAll();
            emit humDataReceived(QString(data));
        });
}

humthread::~humthread()
{
    socket->disconnectFromHost();
    socket->deleteLater(); // 确保 socket 被删除
}

void humthread::run()
{
        // 在 run() 方法中进行连接
       socket->connectToHost("192.168.2.56", 8888);
       if (!socket->waitForConnected(3000)) {
           qDebug() << "连接失败<Get hum Port:8888>：" << socket->errorString();
           return; // 连接失败时退出线程
       }

}
